<%@page import="com.nebula.common.Const"%>
<%@page import="com.nebula.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
	User user = (User) session.getAttribute(Const.USERINFO);
 %>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="static/html5shiv.js"></script>
<script type="text/javascript" src="static/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/layer/2.4/skin/layer.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/magic-input.min.css" />
<!--[if IE 6]>
<script type="text/javascript" src="static/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>个人资料</title>
<style type="text/css">
.pointer{
	cursor: pointer;
}
</style>
</head>
  
<body>
<article class="page-container">
	<form class="form form-horizontal" id="information" action="" name="frm" onsubmit="return false;">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>用户名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" name="username" id="username" readonly="readonly"
					value="<%=user.getUsername()%>" style="width: 800">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>昵称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" autocomplete="off" id="nickname"
					name="nickname" value="<%=user.getNickname()%>" 
					style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>真实姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" autocomplete="off" id="realname"
					name="realname" value="<%=user.getRealname()%>" 
					style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>手机号码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" autocomplete="off" id="phone"
					name="phone" value="<%=user.getPhone()%>" 
					style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>邮箱：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" autocomplete="off" id="email"
					name="email" value="<%=user.getEmail()%>" 
					style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>性别：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input class="mgr mgr-primary" id="man" type="radio"
				 name="sex" value="男">
				<label for="man" class="pointer">男</label>&nbsp;&nbsp;
				<input class="mgr mgr-primary" id="women" type="radio"
				 name="sex" value="女">
				<label for="women" class="pointer">女</label>&nbsp;&nbsp;
				<input class="mgr mgr-primary" id="secret" type="radio"
				 name="sex" value="保密">
				<label for="secret" class="pointer">保密</label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>生日：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" autocomplete="off" id="birthday"
					name="birthday" value="1990-01-01" style="width: 800" 
					onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;"
					onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存修改&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$("input[name=sex]").each(function(i){
		var sex = "<%=user.getSex()%>";
		if($(this).val() == sex){
			$(this).prop("checked","checked");
		}
	});
	
	$.validator.addMethod("checkEmail",function(value,element){
		var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		return this.optional(element) || (reg.test(value));
	},"请输入正确的邮箱");
	$.validator.addMethod("checkNickname",function(value,element){
		var reg = /^[\u4e00-\u9fa50-9A-Za-z]+$/;
		return this.optional(element) || (reg.test(value));
	},"昵称只能为中英文和数字，不包含特殊字符");
	$.validator.addMethod("checkRealname",function(value,element){
		var reg = /^[\u4e00-\u9fa5A-Za-z]+$/;
		return this.optional(element) || (reg.test(value));
	},"真实姓名只能为中英文，不包含特殊字符");
	$.validator.addMethod("checkPhone",function(value,element){
		var length = value.length;
		var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
		return this.optional(element) || (length == 11 && mobile.test(value));
	},"请输入正确的手机号码");
	$("#information").validate({
		onfocusout:function(element){
			$(element).valid();
		},
		rules:{
			nickname:{
				required:false,
				checkNickname:true,
				maxlength: 12,
				remote : {
					url : "${pageContext.request.contextPath}/user/check-information.action",
					type : "post",
					data : {
						str : function(){
							return $('#nickname').val();
						},
						type : "nickname"
					},
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				}
			},
			realname:{
				required:false,
				checkRealname:true,
				maxlength: 12
			},
			phone:{
				required: false,
				checkPhone:true,
				remote : {
					url : "${pageContext.request.contextPath}/user/check-information.action",
					type : "post",
					data : {
						str : function(){
							return $('#phone').val();
						},
						type : "phone"
					},
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				}
			},
			email:{
				required:true,
				checkEmail: true,
				remote : {
					url : "${pageContext.request.contextPath}/user/check-information.action",
					type : "post",
					data : {
						str : function(){
							return $('#email').val();
						},
						type : "email"
					},
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				}
			}
		},
		messages:{
			email : {
				remote : "邮箱已存在"
			},
			phone : {
				remote : "手机号码已存在"
			},
			nickname : {
				remote : "昵称已存在"
			}
		},
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		submitHandler:function(){
			$.post("${pageContext.request.contextPath}/user/update-information.action",$('#information').serialize(),function(data){
				if(data.status == 0){
					$.ajax({
						type: "post",
						url: "${pageContext.request.contextPath}/user/endecodLogin.action",
						data: {
							username : '<%=user.getUsername()%>',
							password : '<%=user.getPassword()%>',
						},
						dataType: "json",
						success: function(_data){
						}
					});
					layer.msg(data.msg,{icon: 6,time:2000});
				} else{
					layer.msg(data.msg,{icon:5});
				}
			})
		}
	});
});
</script>
</body>
</html>
